package com.yunfeisoft.business.model;

import com.applet.base.ServiceModel;
import com.applet.sql.record.TransientField;
import com.applet.utils.DateUtils;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * ClassName: SmsCoupon
 * Description: 优惠卷表
 *
 * @Author: Jackie liu
 * Date: 2020-06-02
 */
@Entity
@Table(name = "SMS_COUPON")
public class SmsCoupon extends ServiceModel implements Serializable {

    /**
     * Field serialVersionUID: 序列号
     */
    private static final long serialVersionUID = 1L;

    /**
     * 优惠卷类型；0->全场赠券；1->会员赠券；2->购物赠券；3->注册赠券
     */
    @Column
    private Integer type;

    /**
     * 名称
     */
    @Column
    private String name;

    /**
     * 使用平台：0->全部；1->移动；2->PC'
     */
    @Column
    private Integer platform;

    /**
     * 数量
     */
    @Column
    private Integer count;

    /**
     * 金额
     */
    @Column
    private BigDecimal amount;

    /**
     * 每人限领张数
     */
    @Column
    private Integer perLimit;

    /**
     * 使用门槛；0表示无门槛
     */
    @Column
    private BigDecimal minPoint;

    /**
     * 开始时间
     */
    @Column
    private Date startTime;

    public String getStartTimeStr() {
        if (startTime == null) {
            return null;
        }
        return DateUtils.dateTimeToString(startTime);
    }

    /**
     * 结束时间
     */
    @Column
    private Date endTime;

    public String getEndTimeStr() {
        if (endTime == null) {
            return null;
        }
        return DateUtils.dateTimeToString(endTime);
    }


    /**
     * 使用类型：0->全场通用；1->指定分类；2->指定商品
     */
    @Column
    private Integer useType;

    /**
     * 备注
     */
    @Column
    private String note;

    /**
     * 发行数量
     */
    @Column
    private Integer publishCount;

    /**
     * 已使用数量
     */
    @Column
    private Integer useCount;

    /**
     * 领取数量
     */
    @Column
    private Integer receiveCount;

    /**
     * 可以领取的日期
     */
    @Column
    private Date enableTime;

    /**
     * 优惠码
     */
    @Column
    private String code;

    /**
     * 可领取的会员类型：0->无限时
     */
    @Column
    private Integer memberLevel;

    @TransientField
    private List<Map<String, Object>> typeList;
    @TransientField
    private List<Map<String, Object>> platformList;
    @TransientField
    private List<SmsCouponProductCategoryRelation> categoryRelationList;
    @TransientField
    private List<SmsCouponProductRelation> productRelationList;
    @TransientField
    private List<SmsCouponHistory> couponHistoryList;

    public List<SmsCouponHistory> getCouponHistoryList() {
        return couponHistoryList;
    }

    public void setCouponHistoryList(List<SmsCouponHistory> couponHistoryList) {
        this.couponHistoryList = couponHistoryList;
    }

    public List<SmsCouponProductCategoryRelation> getCategoryRelationList() {
        return categoryRelationList;
    }

    public void setCategoryRelationList(List<SmsCouponProductCategoryRelation> categoryRelationList) {
        this.categoryRelationList = categoryRelationList;
    }

    public List<SmsCouponProductRelation> getProductRelationList() {
        return productRelationList;
    }

    public void setProductRelationList(List<SmsCouponProductRelation> productRelationList) {
        this.productRelationList = productRelationList;
    }

    public List<Map<String, Object>> getPlatformList() {
        return platformList;
    }

    public void setPlatformList(List<Map<String, Object>> platformList) {
        this.platformList = platformList;
    }

    public List<Map<String, Object>> getTypeList() {
        return typeList;
    }

    public void setTypeList(List<Map<String, Object>> typeList) {
        this.typeList = typeList;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getPlatform() {
        return platform;
    }

    public void setPlatform(Integer platform) {
        this.platform = platform;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public Integer getPerLimit() {
        return perLimit;
    }

    public void setPerLimit(Integer perLimit) {
        this.perLimit = perLimit;
    }

    public BigDecimal getMinPoint() {
        return minPoint;
    }

    public void setMinPoint(BigDecimal minPoint) {
        this.minPoint = minPoint;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Integer getUseType() {
        return useType;
    }

    public void setUseType(Integer useType) {
        this.useType = useType;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public Integer getPublishCount() {
        return publishCount;
    }

    public void setPublishCount(Integer publishCount) {
        this.publishCount = publishCount;
    }

    public Integer getUseCount() {
        return useCount;
    }

    public void setUseCount(Integer useCount) {
        this.useCount = useCount;
    }

    public Integer getReceiveCount() {
        return receiveCount;
    }

    public void setReceiveCount(Integer receiveCount) {
        this.receiveCount = receiveCount;
    }

    public Date getEnableTime() {
        return enableTime;
    }

    public void setEnableTime(Date enableTime) {
        this.enableTime = enableTime;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getMemberLevel() {
        return memberLevel;
    }

    public void setMemberLevel(Integer memberLevel) {
        this.memberLevel = memberLevel;
    }


    public String getUseTypeStr() {
        if (useType == null) {
            return null;
        }
        return CouponUseTypeEnum.valueOf(this.useType);
    }

    /**
     * 使用类型：0->全场通用；1->指定分类；2->指定商品
     */
    public enum CouponUseTypeEnum {

        UNIVERSAL(0, "全场通用"),
        DESIGNATED_CLASSIFICATION(1, "指定分类"),
        DESIGNATED_PRODUCT(2, "指定商品");

        private int value;
        private String label;

        private CouponUseTypeEnum(int value, String label) {
            this.value = value;
            this.label = label;
        }

        public static String valueOf(Integer value) {
            if (value == null) {
                return null;
            }
            for (SmsCoupon.CouponUseTypeEnum loop : SmsCoupon.CouponUseTypeEnum.values()) {
                if (value == loop.getValue()) {
                    return loop.getLabel();
                }
            }
            return null;
        }

        public int getValue() {
            return value;
        }

        public String getLabel() {
            return label;
        }

    }


    public String getPlatformStr() {
        if (platform == null) {
            return null;
        }
        return CouponPlatformEnum.valueOf(this.platform);
    }

    /**
     * 使用平台：0->全部；1->移动；2->PC'
     */
    public enum CouponPlatformEnum {

        ALL(0, "全部"),
        MOBILE(1, "移动"),
        PC(2, "PC");

        private int value;
        private String label;

        private CouponPlatformEnum(int value, String label) {
            this.value = value;
            this.label = label;
        }

        public static String valueOf(Integer value) {
            if (value == null) {
                return null;
            }
            for (SmsCoupon.CouponPlatformEnum loop : SmsCoupon.CouponPlatformEnum.values()) {
                if (value == loop.getValue()) {
                    return loop.getLabel();
                }
            }
            return null;
        }

        public int getValue() {
            return value;
        }

        public String getLabel() {
            return label;
        }

    }


    public String getTypeStr() {
        if (type == null) {
            return null;
        }
        return CouponTypeEnum.valueOf(this.type);
    }

    /**
     * 优惠卷类型；0->全场赠券；1->会员赠券；2->购物赠券；3->注册赠券
     */
    public enum CouponTypeEnum {

        WHOLE_AUDIENCE(0, "全场赠券"),
        MEMBER(1, "会员赠券"),
        SHOPPING(2, "购物赠券"),
        REGISTER(3, "注册赠券");

        private int value;
        private String label;

        private CouponTypeEnum(int value, String label) {
            this.value = value;
            this.label = label;
        }

        public static String valueOf(Integer value) {
            if (value == null) {
                return null;
            }
            for (SmsCoupon.CouponTypeEnum loop : SmsCoupon.CouponTypeEnum.values()) {
                if (value == loop.getValue()) {
                    return loop.getLabel();
                }
            }
            return null;
        }

        public int getValue() {
            return value;
        }

        public String getLabel() {
            return label;
        }

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SmsCoupon smsCoupon = (SmsCoupon) o;
        return Objects.equals(type, smsCoupon.type) &&
                Objects.equals(name, smsCoupon.name) &&
                Objects.equals(platform, smsCoupon.platform) &&
                Objects.equals(count, smsCoupon.count) &&
                Objects.equals(amount, smsCoupon.amount) &&
                Objects.equals(perLimit, smsCoupon.perLimit) &&
                Objects.equals(minPoint, smsCoupon.minPoint) &&
                Objects.equals(startTime, smsCoupon.startTime) &&
                Objects.equals(endTime, smsCoupon.endTime) &&
                Objects.equals(useType, smsCoupon.useType) &&
                Objects.equals(note, smsCoupon.note) &&
                Objects.equals(publishCount, smsCoupon.publishCount) &&
                Objects.equals(useCount, smsCoupon.useCount) &&
                Objects.equals(receiveCount, smsCoupon.receiveCount) &&
                Objects.equals(enableTime, smsCoupon.enableTime) &&
                Objects.equals(code, smsCoupon.code) &&
                Objects.equals(memberLevel, smsCoupon.memberLevel) &&
                Objects.equals(typeList, smsCoupon.typeList) &&
                Objects.equals(platformList, smsCoupon.platformList) &&
                Objects.equals(categoryRelationList, smsCoupon.categoryRelationList) &&
                Objects.equals(productRelationList, smsCoupon.productRelationList) &&
                Objects.equals(couponHistoryList, smsCoupon.couponHistoryList);
    }

    @Override
    public int hashCode() {
        return Objects.hash(type, name, platform, count, amount, perLimit, minPoint, startTime, endTime, useType, note, publishCount, useCount, receiveCount, enableTime, code, memberLevel, typeList, platformList, categoryRelationList, productRelationList, couponHistoryList);
    }
}